directives.directive('entry', ["$rootScope", "tools", "$timeout", "$location", function ($rootScope, tools, $timeout, $location) {
    return {
        restrict: 'AE',
        scope: {},
        replace: true,
        link: function (scope, element, attr) {
            $timeout(function () {
                $(element).find('.entryBtn').popup({
                        inline: false,
                        hoverable: true,
                        popup: '.popup-entry',
                        position: 'bottom left',
                        onShow: function () {
                            $(element).find('.popup-container').removeClass('none');
                        },
                        onHide: function () {
                            $(element).find('.popup-container').addClass('none');
                        }
                    }
                );
            }, 1000);

            var entries = {
                'dbManager': {
                    name: '数据管理',
                    icon: 'database icon',
                    shown: true,
                    fn: function () {
                        scope.shown = false;
                        $location.url('/dbManager');
                    }
                },
                "pages": {
                    name: '查看报表',
                    icon: 'copy icon',
                    shown: true,
                    fn: function () {
                        scope.shown = false;
                        $location.url('/pages');
                    }
                },
                'entry': {
                    name: '回到首页',
                    icon: "list layout icon",
                    shown: true,
                    fn: function () {
                        scope.shown = false;
                        $location.url('/entry');
                    }
                },
                'sysManager': {
                    name: '系统管理',
                    icon: 'setting icon',
                    shown: true,
                    fn: function () {
                        $location.url('/sysManager');
                    }
                },
                "quit": {
                    name: '退出登陆',
                    icon: 'sign out icon',
                    shown: true,
                    fn: function () {
                        window.location.href = '/trend-new-BI/main.html';
                        // window.location.reload();
                    }
                }
            };

            scope.shown = true;
            scope.entries = [];
            $rootScope.$on('$locationChangeSuccess', function () {
                listEntries();
            });

            $rootScope.$on('PREVIEW_EV', function () {
                scope.shown = false;
            });

            $rootScope.$on('PREVIEW_OFF_EV', function () {
                scope.shown = true;
            });

            function listEntries () {
                var hash = window.location.hash.slice(2);
                scope.entries = angular.copy(entries);
                scope.shown = true;

                if (hash == 'editor') {

                } else if (hash == 'pages') {
                    scope.entries['pages'].shown = false;
                } else if (hash == 'entry') {
                    scope.entries['pages'].shown = false;
                } else if (hash == 'dbManager') {
                    scope.entries['dbManager'].shown = false;
                } else if (hash == 'login' || hash == 'entry' || hash == 'mlogin') {
                    scope.shown = false;
                } else if (hash == 'sysManager') {
                    scope.entries.sysManager.shown = false;
                }
            }

            listEntries();
        },
        templateUrl: "/trend-new-BI/app/components/entrys/entry/entryView.html"
    }
}]);